package com.bite.friend.controller.exam;


import com.bite.common.core.controller.BaseController;
import com.bite.common.core.domain.R;
import com.bite.common.core.domain.TableDataInfo;

import com.bite.friend.domain.exam.dto.ExamQueryDTO;
import com.bite.friend.service.exam.IExamService;
import jakarta.validation.constraints.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/exam")
@RestController
public class ExamController extends BaseController {
    @Autowired
    private IExamService examService;

    // 通过MySQL 来查询
    @GetMapping("/semiLogin/list")
    public TableDataInfo list(ExamQueryDTO examQueryDTO) {
//        startPage(examQueryDTO);
        return getTableDataInfo(examService.list(examQueryDTO));
    }

    @GetMapping("/semiLogin/redis/list")
    public TableDataInfo redisList(ExamQueryDTO examQueryDTO) {
//        startPage(examQueryDTO); // 不能加这个 因为如果要刷新数据库的时候 那么就是需要获取所有的值
        return examService.redisList(examQueryDTO);
    }

    @GetMapping("/getExamFirstQuestion")
    public R<String> getExamFirstQuestion(Long examId) {
        return ok(examService.getExamFirstQuestion(examId));
    }

    @GetMapping("/preQuestion")
    public R<String> preQuestion(@NotNull(message = "竞赛Id不能为空") Long examId, @NotNull(message = "题目Id不能为空") Long questionId) {
        return ok(examService.preQuestion(examId, questionId));
    }

    @GetMapping("/nextQuestion")
    public R<String> nextQuestion(@NotNull(message = "竞赛Id不能为空") Long examId, @NotNull(message = "题目Id不能为空") Long questionId) {
        return ok(examService.nextQuestion(examId, questionId));
    }
}
